package za.org.jcicada.genss.sensor.impl;

import za.org.jcicada.genss.sensor.ISensorType;

/**
 * Boolean sensor type
 * @author rcrida
 */
public class TypeBoolean implements ISensorType {
	private static final long serialVersionUID = 1L;
	
    /**
     * Singleton instance of TypeBoolean.
     */
    static private final TypeBoolean instance = new TypeBoolean();
    
    /**
     * Factory method used to access instance of TypeBoolean
     * @return an instance of TypeBoolean
     */
    static public TypeBoolean getInstance() {
        return instance;
    }
    
    /**
     * Factory method used to access instance of TypeBoolean
     * @param ignored
     * @return an instance of TypeBoolean
     */
    static public TypeBoolean getInstance(String[] args) {
        return instance;
    }
    
    /**
     * Private constructor forces use of getInstance().
     */
    private TypeBoolean() {
    }
    
    /**
     * Check if the specified value is an instance of Boolean
     */
    public boolean isValid(Object value) {
        return value instanceof Boolean;
    }
    
    @Override
    public String toString() {
    	return "Boolean";
    }
    
    @Override
    public boolean equals(Object aOther) {
        if (this == aOther) return true;
        return aOther instanceof TypeBoolean;
    }
    
    @Override
    public int hashCode() {
        return 0;
    }

    public String[] toStringArray() {
        return new String[]{};
    }

    public Object valueOf(String string) {
        return Boolean.valueOf(string);
    }
    
    public double doubleValueOf(Object value) {
    	return ((Boolean) value).booleanValue() == false ? 0.0 : 1.0;
    }

}
